package com.yingpai.fitness.dvp_2_0.main.activity.mine;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.lzy.okgo.model.HttpParams;
import com.lzy.okgo.model.Response;
import com.yingpai.fitness.R;
import com.yingpai.fitness.base.BaseResponse;
import com.yingpai.fitness.dvp_2_0.common.activity.CommonActivity;
import com.yingpai.fitness.dvp_2_0.common.finalokgo.callback.Callback;
import com.yingpai.fitness.dvp_2_0.common.finalokgo.request.RequestType;
import com.yingpai.fitness.dvp_2_0.common.util.SharedPreferencesHelp;
import com.yingpai.fitness.dvp_2_0.common.util.constant.Contacts;
import com.yingpai.fitness.dvp_2_0.main.util.constant.Constant;
import com.yingpai.fitness.dvp_2_0.main.util.constant.Url;
import com.yingpai.fitness.entity.wx.TokenBean;

import butterknife.BindView;
import butterknife.OnClick;


public class AccountSecurityActivity extends CommonActivity {


    @BindView(R.id.input_old_pass_et)
    EditText inputOldPassEt;
    @BindView(R.id.input_new_pass_et)
    EditText inputNewPassEt;
    @BindView(R.id.input_new_pass_et_again)
    EditText inputNewPassEtAgain;
    private TokenBean token;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStatusFlag(Contacts.NORMAL_STATUS);
        setContentView(R.layout.account_security_activity);
    }

    @Override
    protected void initView() {
        setTitle("账户安全");

        token = ((TokenBean) (SharedPreferencesHelp.getBean(Constant.TOKENBEAN)));
    }

    @Override
    protected void initData() {

    }


    @Override
    @OnClick({R.id.modification_pass_submit_btn})
    public void onViewClicked(View view) {
        super.onViewClicked(view);
        switch (view.getId()) {
            case R.id.modification_pass_submit_btn:
                if (!TextUtils.isEmpty(inputOldPassEt.getText().toString().trim())) {
                    if (!TextUtils.isEmpty(inputNewPassEt.getText().toString().trim())) {
                        if (!TextUtils.isEmpty(inputNewPassEtAgain.getText().toString().trim())) {
                            showDialog(this, null);
                            HttpParams params = new HttpParams();
                            params.put("customerId", token.getId());
                            params.put("oldPassword", inputOldPassEt.getText().toString().trim());
                            params.put("newPassword", inputNewPassEt.getText().toString().trim());
                            params.put("confirmPassword", inputNewPassEtAgain.getText().toString().trim());
                            finalOkGo.request(RequestType.POST, Contacts.HOST_SERVER + Url.RESET_PASSWORD, params, Url.RESET_PASSWORD, new Callback<BaseResponse>() {
                                @Override
                                public void onSuccess(BaseResponse baseResponse) {
                                    dismissDialog();
                                    if (baseResponse.getResult().equals(Constant.REQUEST_SUCCESS)) {
                                        showToast("修改密码成功");
                                        finishActivity();
                                    } else {
                                        showToast(baseResponse.getMsg());
                                    }
                                }

                                @Override
                                public void onError(Response<String> response) {
                                    super.onError(response);
                                    dismissDialog();
                                }
                            });
                        } else {
                            showToast("请填写确认密码");
                        }
                    } else {
                        showToast("请填写新密码");
                    }
                } else {
                    showToast("请填写旧密码");
                }
                break;
        }
    }
}
